from apiBatchCallTask import *

recentBatchId = 0
def getRecentBatchId():
    return recentBatchId

def createBatchCallBatchTest(dataType):
    task_id = 0
    if getRecentTaskId() == 0:
        task_id = createBatchCallTaskTest("json")
        task_id = createBatchCallTaskTest("xml")
    else:
        task_id = getRecentTaskId()

    authType = 1
    operation = "BatchCalls"
    function = "addNewBatch"

    params = {
        "taskId": task_id,
        "unique_task_ids": "112,22,32,42",
        #   "gid":gid,
        "tels": [
            {
                "customerTel": "15861800293",
                "customerName": "张三",
                "userData": "张三测试"
            },
            {
                "customerTel": "02557926532",
                "customerName": "黄琳",
                "userData": "黄琳测试"
            },
        ],
    }
    f = ApiPost(auth_info, domain, version, dataType)

    f.set_func_mode(operation, function, authType)
    rsp_dic = f.post_info_to_api(params)

    print(rsp_dic)
    try:
        global recentBatchId
        if rsp_dic['resp']['respCode'] != 0 and rsp_dic['resp']['respCode'] != '0':
            print("Error, please check and retry")
        recentBatchId = int(rsp_dic['resp']['addNewBatch']['batchId'])
        return recentBatchId
    except Exception as e:
        print(e)
        return -1